package com.zfcer.chapter03;

/**
 * @Classname Stack
 * @Description 栈实现
 * @Created by zfcer
 * @Date 2022/4/19 13:12
 */
public class Stack {
    private final static int SIZE = 100;
    private int[] arr;
    private int top;

    public void init(){
        arr = new int[SIZE];
        top = 0;
    }

    public boolean push(int val){
        if(top >= SIZE){
            // 达到最大容量
            return false;
        }
        arr[top++] = val;
        return true;
    }

    public int pop(){
        if(top <= 0) return 0;
        return arr[--top];
    }

    public int peek(){
        if(top <= 0) return 0;
        return arr[top-1];
    }
}
